/**
 * 用户管理 sys:user:management
 * 角色管理 sys:role:management
 * 权限管理 sys:permission:management
 * 部门管理 sys:department:management
 * 设备管理 device:management
 * 生产管理 produce:management
 * 交互中心 interactive:management
 */
 export const menuList = [
  {
    index: '/main',
    title: '概况',
    icon: 'icon-list',
    permission: [
      'sys:main:management',
      'sys:main:add',
      'sys:main:update',
      'sys:main:delete',
      'sys:main:query',
    ],
  },
  {
    index: 'organization',
    title: '系统管理',
    icon: 'icon-organization',
    children: [
      {
        index: '/organization/menu',
        title: '菜单管理',
        icon: 'icon-company',
        permission: [
          'sys:menu:management',
          'sys:menu:add',
          'sys:menu:update',
          'sys:menu:delete',
          'sys:menu:query',
        ],
      },
      {
        index: '/organization/role',
        title: '角色管理',
        icon: 'icon-detail',
        permission: [
          'sys:role:management',
          'sys:role:add',
          'sys:role:update',
          'sys:role:delete',
          'sys:role:query',
        ],
      },
      {
        index: '/organization/user',
        title: '用户管理',
        icon: 'icon-account',
        permission: [
          'sys:user:management',
          'sys:user:add',
          'sys:user:update',
          'sys:user:delete',
          'sys:user:query',
        ],
      },
    ],
  },
  {
    index: '/device',
    title: '设备管理',
    icon: 'icon-device',
    permission: 'device:management'
  },
  {
    index: '/product',
    title: '产品管理',
    icon: 'icon-product',
    permission: 'product:management'
  },
  {
    index: 'mobile-user-manage',
    title: '用户管理',
    icon: 'icon-account',
    children: [
      {
        index: '/mobile-user/total',
        title: '用户概况',
        icon: 'icon-point',
        permission: [
          'mobile-user-manage:total:management',
          'mobile-user-manage:total:add',
          'mobile-user-manage:total:update',
          'mobile-user-manage:total:delete',
          'mobile-user-manage:total:query',
        ],
      },
      {
        index: '/mobile-user/list',
        title: '用户列表',
        icon: 'icon-avatar',
        permission: [
          'mobile-user-manage:list:management',
          'mobile-user-manage:list:add',
          'mobile-user-manage:list:update',
          'mobile-user-manage:list:delete',
          'mobile-user-manage:list:query',
        ],
      },
    ],
  },
];

export default {
  _getMenuList(menuList, permissions) {
    return menuList.filter((menuItem) => {
      if (menuItem.permission) {
        if (typeof menuItem.permission === 'string') {
          return permissions.indexOf(menuItem.permission) !== -1;
        } else {
          return menuItem.permission.some((perm) => permissions.indexOf(perm) !== -1);
        }
      }
      return true;
    });
  },
  getMenuList(permissions) {
    const _menuList = this._getMenuList(JSON.parse(JSON.stringify(menuList)), permissions);
    _menuList.forEach((menuItem) => {
      if (menuItem.children) {
        menuItem.children = this._getMenuList(menuItem.children, permissions);
      }
    });
    return _menuList.filter((menuItem) => {
      if (menuItem.children) {
        if (menuItem.children.length > 0) {
          return true;
        }
        return false;
      }
      return true;
    });
  },
};
